home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / Powervisor v1.10b disk2.adf / Scripts < prev    next >
Text File  |  1991-09-22  |  14KB  |  348 lines

  1. *-----------------*
  2. * Tutor : Scripts * Sun Sep 22 11:31:37 1991
  3. *-----------------*
  4.  
  5. ===================== Commands used in this tutorial =========================
  6.  
  7.    assign      Assign to a variable for use in ARexx
  8.    attach      Attach a command to a key (make a macro)
  9.    awin        Open/close 'Rexx' logical window
  10.    cleanup     Free all memory allocated with 'alloc'
  11.    front       Bring PowerVisor to the front
  12.    go          Jump to memory
  13.    hide        Hide output from ARexx script
  14.    list        List a list
  15.    load        Load a file in memory
  16.    pvcall      Call PowerVisor internal function
  17.    remattach   Remove a macro
  18.    remvar      Remove a variable
  19.    resident    Make a ML-script resident
  20.    rx          Start an ARexx script
  21.    script      Start a script
  22.    string      Convert a PowerVisor string pointer to an ARexx string
  23.    sync        Synchronize ARexx with PowerVisor
  24.    unhide      Unhide output from ARexx script
  25.    unresident  Remove a resident ML-script
  26.    unsync      Undo synchronization of ARexx with PowerVisor
  27.    vars        Show all variables
  28.    void        Evaluate expressions
  29.  
  30.  
  31. ===================== Functions used in this tutorial ========================
  32.  
  33.    alloc       Allocate memory
  34.    eval        Evaluate string
  35.    free        Free memory
  36.    if          Conditional evaluation
  37.  
  38.  
  39. ============================== Introduction ==================================
  40.  
  41. This tutor file explains everything (or almost everything at least) that
  42. there is to know about ³scripts for PowerVisor. This is already quiet a lot.
  43. ²ARexx scripts, ²PowerVisor scripts and ²machinelanguage scripts are all
  44. explained here.
  45.  
  46.  
  47. =========================== PowerVisor scripts ===============================
  48.  
  49. ²²PowerVisor scripts are the simplest. A PowerVisor script is simply a bunch
  50. of PowerVisor commands put after each other. You can't do special things
  51. in scripts like goto's, subroutines, if-then-else structures, ....
  52. There are a few things that must be noted though :
  53.  
  54.    - You can put ¹comments in your script files by putting a ';' in front
  55.      of the line (you may put spaces in front of the ';')
  56.      Note that you can't put comments after a command, unless you are
  57.      sure that the command will ignore the extra argument (most commands
  58.      ignore everything after the last argument they need, but there
  59.      are exceptions)
  60.  
  61.          ;  this is a comment
  62.  
  63.    - The 'quit' command works different in scripts. The 'quit' command
  64.      stops the script. (PowerVisor will not quit)
  65.    - The 'script' command does not work in scripts. You can't recursively
  66.      execute scripts
  67.  
  68. You can start a script with the 'script' command.
  69.  
  70. The recommended place for scripts is the ¹s:pv subdirectory but PowerVisor
  71. will first try the ²current directory. When a script is located in the
  72. current directory or in the s:pv directory you need not specify the full
  73. pathname.
  74.  
  75. There is one exception. The ¹PowerVisor-Startup script always resides
  76. in the s: directory. This is the script that is executed everytime
  77. you start PowerVisor. The standard PowerVisor-startup script provided
  78. with this release of PowerVisor defines some ¹aliases (extra commands)
  79. and makes some ¹macros (²key attachements) for you.
  80.  
  81. There are some commands and functions present in PowerVisor that can
  82. be used from the PowerVisor commandline but are more useful in scripts.
  83. Two of these functions are 'if' and 'eval'. They are explained more fully
  84. in the 'Expressions' tutorial file.
  85.  
  86. Of course, commands like 'print' and 'locate' are also more useful in
  87. scripts.
  88.  
  89. For a fully documented script example, look at ¹Source/mkeys.explained.
  90. This script installs a memory viewer. Don't be alarmed at the apparent
  91. complexity of this script (well, you may alarm yourselves a bit, because
  92. it is a complex example :-), once you got the feeling you will find it
  93. rather easy to use scripts in general.
  94.  
  95. If you use ¹variables in your script it is recomended that you put
  96. an ¹underscore ('_') in front of your variable. That way you minimize
  97. the chances for variable collision with user variables. If you are
  98. ready with the variable use 'remvar' to remove it.
  99.  
  100.  
  101. ============================== ARexx scripts =================================
  102.  
  103. For more complex scripts you can use ¹¹ARexx. With ARexx you can interface
  104. PowerVisor to all other programs that use ARexx. If you want you could even
  105. write an ARexx script to debug programs from within your favorite editor,
  106. or edit files from within PowerVisor :-)
  107.  
  108. The ³³PowerVisor ARexx port is called ¹¹'REXX_POWERVISOR'. This port is
  109. the default ARexx port if your script is started from PowerVisor. But
  110. if you want to make global scripts (scripts that can be started from
  111. anywhere, like the Shell or an editor) you must use :
  112.  
  113. ARexx< address rexx_powervisor
  114.  
  115. before you issue any PowerVisor command.
  116.  
  117. You can of course also use :
  118.  
  119. ARexx< address rexx_powervisor 'some powervisor command'
  120.  
  121. (Note that an ARexx script always starts with a comment /* ... */)
  122.  
  123.  
  124. Almost all PowerVisor commands can be used from within an ARexx script.
  125. There are some differences compared with the commandline :
  126.  
  127.    - You can't use ¹abbreviations for commands, you must always type the
  128.      full commandname
  129.    - You can't use ¹prefixes like '-' and '~' before a command. ('~' is
  130.      not useful). If you want to ²hide output ('-'), you must use the
  131.      'hide' command provided for that purpose
  132.    - The 'quit' command does not work
  133.    - You get some new commands ('assign', 'hide', 'unhide', 'sync',
  134.      'string', 'async' and 'front') (explained below). These command
  135.      also work on the PowerVisor commandline but are not very useful there
  136.    - ¹Functions are called the same way as commands. The result is put
  137.      in the ²'result' variable (if you use ²'options results' in
  138.      the ARexx script)
  139.    - Note that some commands and functions return a string instead of
  140.      a number when called from ARexx (See the 'CommandReference' file
  141.      and 'Functions' file for all commands and functions returning strings)
  142.  
  143.  
  144. You can use the 'rx' command to start an ARexx script. This command
  145. starts the script ¹asynchronous. This means that while the script is
  146. running you can still use PowerVisor commands. If you want to disable
  147. this feature you can use the 'sync' command from within the ARexx
  148. script. This command ²synchronizes PowerVisor with the ARexx script.
  149. You will not be able to use the PowerVisor commandline. When the
  150. ARexx script is ready, it should call 'async'. If the ARexx script
  151. forgets the 'async' command, you will not be able to use PowerVisor
  152. anymore. You can solve this by sending the command 'async' from
  153. the Shell (with the 'rx' shell command) :
  154.  
  155.    Shell< rx "address rexx_powervisor async" <enter>
  156.  
  157.  
  158. Note that the ³default file extension for PowerVisor ARexx scripts
  159. is ¹'.pv'. You do not need to type this extension when you use the
  160. PowerVisor 'rx' command.
  161.  
  162. When you execute a PowerVisor command or function from within ARexx
  163. and there is an error (or the command is interrupted) you can
  164. examine the returncode (the 'rc' variable). 'rc' will contain
  165. 0 if there was no error or the PowerVisor error code if there was
  166. an error. You can find all PowerVisor error codes in the 'Functions'
  167. reference file listed with the 'geterror' function.
  168.  
  169. Because you can't use the '-' prefix to ²hide output for a command there
  170. is another way to hide output. The 'hide' and 'unhide' commands are
  171. provided for this. After 'hide' all output from the ARexx commands is
  172. hidden (as if there was a '-' in front of the commandline).
  173. 'unhide' restores this situation. Note that you must use 'unhide' otherwise
  174. you might confuse yourselves when you use other ARexx scripts.
  175.  
  176. Normally the output for the ARexx scripts goes to the ³current logical window
  177. ('Main' or 'Extra'). If you open the ³'Rexx' logical window with 'awin',
  178. all the ARexx output will go to that logical window.
  179.  
  180. The 'front' command brings the ²PowerVisor screen to the front.
  181.  
  182. Normally you would use 'rx' to start ARexx scripts. But you can also
  183. use this command to start ARexx commands from within PowerVisor :
  184.  
  185. < rx 'disp 3+4' <enter>
  186. > 00000007 , 7
  187.  
  188. or something more useful :
  189.  
  190. < rx 'address command dir' <enter>
  191. CLI> ...
  192.  
  193. And the directory appears on the shell output window. You can thus use
  194. the 'rx' command to start ²cli commands from within PowerVisor.
  195.  
  196. If you have a pointer to a string in PowerVisor and you want to convert
  197. this pointer to a real ARexx string you can use the 'string' command to
  198. do that.
  199.  
  200.  
  201. The last extra command for ARexx is 'assign'. With this command you
  202. can assign something to a ²PowerVisor variable.
  203. For example, the following ARexx script :
  204.  
  205.       file< /* */
  206.       file< address rexx_powervisor
  207.       file< a=1
  208.       file< assign 'a=2'
  209.       file< disp a
  210.       file< disp 'a'
  211.  
  212. Will have as output :
  213.  
  214.       < rx file <enter>
  215.       > 00000001 , 1
  216.       > 00000002 , 2
  217.  
  218. You should understand why
  219.    a=1
  220. is not the same as
  221.    assign 'a=1'
  222.  
  223. The first command assigns 1 to the ²ARexx variable 'a'. This variable
  224. is not directly accessable from within PowerVisor.
  225.  
  226. The second command assign 1 to the PowerVisor variable 'a'. This variable
  227. is not directly accesable from within the ARexx script. You can ask the value
  228. of PowerVisor variables with 'void' :
  229.  
  230.    ARexx< options results
  231.    ARexx< a=1
  232.    ARexx< assign 'a=2'
  233.    ARexx< 'void a'
  234.    ARexx< var1=result
  235.    ARexx< 'void' a
  236.    ARexx< var2=result
  237.  
  238. Note ! var1 will be equal to 2, but var2 will be equal to 1. Can you explain
  239. why ?
  240.  
  241. ¹s:pv/ShowAscii.pv, ¹s:pv/PrintMode.pv and ¹s:pv/PrintHist.pv are three ARexx
  242. script examples that you can examine.
  243. ¹s:pv/Assem.pv is a small assembler. This is also a good example but it is
  244. rather large.
  245.  
  246.  
  247. ========================= Machinelanguage scripts ============================
  248.  
  249. The following explanation is rather technical. Most PowerVisor users will
  250. probably never write ²²machinelanguage scripts.
  251.  
  252. Machinelanguage scripts or ML-scripts are normal AmigaDOS executable files.
  253. In practice these can be programmed in several languages (like C), but
  254. for naming conventions we call them ML-scripts.
  255.  
  256. You can execute ML-scripts the same way as normal PowerVisor scripts :
  257. with the 'script' command. PowerVisor will automatically check if the
  258. script is a machinelanguage script by reading the first four bytes.
  259. AmigaDOS executable files always begin with the same four bytes.
  260.  
  261.  
  262. Example :
  263.  
  264. < script execfile 10 <enter>
  265.  
  266. will execute the file 'execfile' and give 10 as the first argument
  267. to the machinelanguage script.
  268.  
  269. When a ml-script gets executed some registers contain predefined
  270. information :
  271.  
  272.    a0       A pointer to the rest of the commandline (to '10' in the
  273.             previous example)
  274.    a1       Is the pointer to the ²'rc' variable. You can use this pointer
  275.             to store results or to get some value. The 'rc' variable is a
  276.             longword
  277.    a2       Is the pointer to the ¹PVCallTable. This is a table with routines
  278.             for you to use. See the 'TheWizardCorner' file for more
  279.             information about the PVCallTable and the 'pvcall' command
  280.  
  281. You can put the returnvalue in d0. This returnvalue will be the result of
  282. the 'script' command.
  283.  
  284. If you are serious about writing ML-scripts in C or machinelanguage you
  285. should look in the PVDevelop subdirectory. This directory contains all
  286. include files and libraries useful for developing ML-scripts.
  287.  
  288. This is really all there is to machinelanguage scripts. But you should
  289. read the 'TheWizardCorner' file if you really want to make more advanced
  290. ML-scripts. ¹Source/SearchHist.asm is an example ML-script. This script can
  291. be installed on a key to provide a history search utility (Note that this
  292. is already done in the standard PowerVisor-startup file provided with this
  293. release of PowerVisor).
  294. The Source subdirectory contains some other examples (in C and
  295. machinelanguage) for ML-scripts. All compiled and assembled forms of these
  296. scripts are in the s:pv subdirectory. The C examples are written for
  297. SAS/C (or Lattice). If you have another compiler (like Aztec-C) you will
  298. probably have to change some things. I'm not sure if you will be able to
  299. use the stubs (in the PVDevelop directory) for non-SAS/C compilers. But
  300. since the source of the stubs is provided it should not be difficult to
  301. addapt them to your needs.
  302.  
  303.  
  304. ======================= Making ML-scripts resident ===========================
  305.  
  306. If you want you can make ²ML-scripts ³resident in memory. This is certainly
  307. a lot faster if you use diskdrives and if the script is big.
  308.  
  309. You can use the 'resident' command to make ML-scripts resident. Here
  310. follows an example :
  311.  
  312. < _a={-resident s:pv/SearchHist} <enter>
  313. < attach 'go \(_a)' 04c 2 e <enter>
  314. < attach 'go \(_a)' 04c 1 e <enter>
  315. < remvar _a <enter>
  316.  
  317. These four commands install the 'SearchHist' ML-script on the shift-arrow
  318. up key. When these four commands are executed you can search in the
  319. PowerVisor history buffer with this key (This sequence of commands can
  320. be found in the PowerVisor-startup file).
  321.  
  322. The first command ('resident') loads the ML-script into memory and assigns
  323. the pointer to the code to the '_a' variable (I assume here that you know
  324. how the group operator works. See the 'Expressions' tutor file if you
  325. don't know it).
  326.  
  327. Using the 'attach' command we attach the 'go' command to the shift-arrow
  328. up key (we make a macro). Note that when 'attach' parses the command
  329. string it will replace \(_a) with the contents of the variable '_a'.
  330. This is the pointer to the code of the ML-script. You may ask why we
  331. didn't use the variable instead of the value of the variable ? This is
  332. because we can know remove the variable since the value of the variable
  333. is burned in the macro string.
  334.  
  335. The last command removes the variable.
  336.  
  337. The 'go' command works very analogous to the 'script' command. The only
  338. difference is that the script must be located in memory instead of a
  339. file. The register conventions are the same.
  340.  
  341. Now you can use <shift>+<up> to search in the ²history buffer. The text
  342. at the left of the cursor in the stringgagdet will remain unchanged. The
  343. script will search all lines beginning with this text.
  344.  
  345. You can use 'unresident' to remove a loaded file. All resident files
  346. are also automatically removed when PowerVisor quits.
  347.  
  348.